package com.teamin.utils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangrui on 2017/7/13.
 */
public class SerializationUtils {
    /**
     * @Author: dulei
     * @Description: str to String[]
     * @Date: 2017/7/17
     * @param str 传递的参数为"[\"13716752446\",\"010-60844040\",\"\"]"
     * @return 返回参数为"13716752446,010-60844040,"
     */
    public static String[] getJsonArrStrFormStrings(String str){
        JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(str);
        int size = jsonArray.size();
        String[] strs = new String[size];
        for (int i=0;i<size;i++){
            strs[i] = (String) jsonArray.get(i);
        }
        return strs;

    }

    /**
     * @Author: yangrui
     * @Description: str to list
     * @Date: 上午10:23 2017/7/13
     */
    public static List getListFromJsonArrStr(String jsonArrStr, Class clazz) {
        JSONArray jsonArr = JSONArray.fromObject(jsonArrStr);
        List list = new ArrayList();
        for (int i = 0; i < jsonArr.size(); i++) {
            list.add(JSONObject.toBean(jsonArr.getJSONObject(i), clazz));
        }
        return list;
    }

}
